import { axios } from '@/service/service'
import { ListReq, roleFormReq } from './types'

export function getRoleList(
  params: ListReq,
  page: number,
  pageSize: number
): any {
  return axios({
    url: '/system/role/list',
    method: 'post',
    data: { ...params, page, pageSize },
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    // @ts-ignore
    transformRequest: (params) => JSON.stringify(params)
  })
}

export function roleForm(params: roleFormReq): any {
  return axios({
    url: '/assets/tableInfo/listTableInfo/',
    method: 'get',
    params: {
      ...params
    }
  })
}

export function createRole(params: roleFormReq): any {
  return axios({
    url: '/system/role/add',
    method: 'post',
    data: { ...params },
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    // @ts-ignore
    transformRequest: (params) => JSON.stringify(params)
  })
}

export function editRole(params: roleFormReq): any {
  return axios({
    url: '/system/role/edit',
    method: 'post',
    data: { ...params },
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    // @ts-ignore
    transformRequest: (params) => JSON.stringify(params)
  })
}

export function deleteRole(ids: number, status: number): any {
  return axios({
    url: '/system/role/remove',
    method: 'post',
    data: { ids: ids, status: status == 0 ? 1 : 0 },
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    // @ts-ignore
    transformRequest: (params) => JSON.stringify(params)
  })
}

export function getRoleListAll(): any {
  return axios({
    url: '/system/role/listAll',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    // @ts-ignore
    transformRequest: (params) => JSON.stringify(params)
  })
}
